--谨慎多虑
local jinshenduolv = fk.CreateSkill {
    name = "mcdh_jinshenduolv",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

jinshenduolv:addEffect('active',{
    target_num = 1,
    target_filter = function(self,player, to_select, selected)
        return not to_select:isKongcheng() and #selected == 0
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter =  function() return false  end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target =effect.tos[1]
        local  cards1 = room:getNCards(6)
        local cards2 =target:getCardIds("h")
        local moveInfos = {}
        if #cards1 > 0 then
            table.insert(moveInfos, {
                ids = cards1,
                toArea = Card.Processing,
                moveVisible = true,
                moveReason = fk.ReasonPut,
                proposer = target,
                skillName = self.name,
            })
        end
        if #cards2 > 0 then
            table.insert(moveInfos, {
                from = target,
                ids = cards2,
                toArea = Card.Processing,
                moveVisible = true,
                moveReason = fk.ReasonPut,
                proposer = target,
                skillName = self.name,
            })
        end
        room:moveCards(table.unpack(moveInfos))
        room:sendLog{
            type = "#jinshenduolv-move",
            from = target.id,
            card = cards2
        }
        local cards = cards1
        table.insertTable(cards,cards2)
        local choice = lib.MaxsuitToString(cards, true)
        local result = room:askForChoice(target, choice, self.name, "")
        local  get = table.filter(cards,function(id) return Fk:getCardById(id):getSuitString(true) == result end)
        room:moveCards({
            ids = get,
            to = target,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonPrey,
            skillName = self.name,
        })
        local dis = table.filter(cards,function(id) return  not table.contains(get,id)  end)
        if #dis ~= 0 then
            room:moveCards({
                ids = dis,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonJustMove,
                skillName = self.name,
            })
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_jinshenduolv"] = "慎行",
    [":mcdh_jinshenduolv"] = "『谨慎多虑』<br>出牌阶段限一次，你可以令一名角色将所有手牌和牌堆顶的六张牌置入处理区，然后其获得其中一种花色最多的牌",
    ["#jinshenduolv-move"] = "%from 的手牌 %card 被置于处理区"
}

return jinshenduolv